package com.neusoft.controller;

import com.neusoft.domain.Data;
import com.neusoft.domain.Order;
import com.neusoft.domain.PageResult;
import com.neusoft.domain.Result;
import com.neusoft.domain.Vo.OrderVo;
import com.neusoft.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/pageSelectOrder")
    public Result pageSelectOrder(@RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize,@RequestParam("userId") String userId,@RequestParam("businessId") Integer businessId){
        PageResult<Order>pageResult=orderService.pageSelectOrder(pageNum,pageSize,userId,businessId);
        return Result.success(pageResult);
    }
    @PutMapping("/changeOrderStatus")
    public Result changeOrderStatus(@RequestBody Order order){
        Integer orderId=order.getOrderId();
        Integer orderStatus = order.getOrderStatus();
        orderService.changeOrderStatus(orderId,orderStatus);
        return Result.success();
    }
    @GetMapping("/getOrderDetailByOrderId/{orderId}")
    public Result getOrderDetailByOrderId(@PathVariable("orderId") Integer orderId){
        OrderVo order =orderService.getOrderDetailByOrderId(orderId);
        return Result.success(order);
    }
    @GetMapping("/getData/{id}")
    public Result getData(@PathVariable Integer id){
        System.out.println(id);
        Data result =orderService.getData(id);
        return Result.success(result);
    }

}
